#Region "File Description"
'-----------------------------------------------------------------------------
' BackgroundScreen.cs
'
' Microsoft XNA Community Game Platform
' Copyright (C) Microsoft Corporation. All rights reserved.
'-----------------------------------------------------------------------------
#End Region

#Region "Using Statements"
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Content
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Audio
Imports Microsoft.Xna.Framework.Media

#End Region

''' <summary>
''' The background screen sits behind all the other menu screens.
''' It draws a background image that remains fixed in place regardless
''' of whatever transitions the screens on top of it may be doing.
''' </summary>
Class BackgroundScreen
	Inherits GameScreen
	#Region "Fields"

	Private delay As Single
	Private content As ContentManager
	Private textureToDisplay As Texture2D = Nothing
	Private textureToDisplay2line As Texture2D = Nothing
	Private backgroundTexture As Texture2D
	Private backgroundToDisplayTexture As Texture2D = Nothing

	Private titleTexture As Texture2D
	Private presentsTexture As Texture2D
	Private authorsTexture As Texture2D
	Private copyrightTexture As Texture2D
	Private text0BackgroudTexture As Texture2D
	Private text1BackgroudTexture As Texture2D
	Private text2BackgroudTexture As Texture2D

	Private TransitionAlphaTitle As Single
	Private numTexture As Integer = 0
	Private numLoops As Integer = 2
    Public music As Song


	#End Region

	#Region "Initialization"


	''' <summary>
	''' Constructor.
	''' </summary>
	Public Sub New()
		delay = 10F
		TransitionOnTime = TimeSpan.FromSeconds(1)
		TransitionOffTime = TimeSpan.FromSeconds(1)
	End Sub


	''' <summary>
	''' Loads graphics content for this screen. The background texture is quite
	''' big, so we use our own local ContentManager to load it. This allows us
	''' to unload before going from the menus into the game itself, wheras if we
	''' used the shared ContentManager provided by the Game class, the content
	''' would remain loaded forever.
	''' </summary>
	Public Overrides Sub Activate(instancePreserved As Boolean)
		If Not instancePreserved Then
			If content Is Nothing Then
				content = New ContentManager(ScreenManager.Game.Services, "Content")
			End If

			'SoundEffect a = content.Load<SoundEffect>("Sounds/dos/story1");
			'SoundEffect  a  = content.Load<SoundEffect>("SONGS/DOS/story1");
#If WINDOWS Then
            music = content.Load(Of Song)(System.Configuration.ConfigurationManager.AppSettings("CONFIG_songs").ToString().ToUpper() & "main theme")
#End If
			'music = content.Load<Song>(System.Configuration.ConfigurationSettings.AppSettings["CONFIG_songs"].ToString().ToUpper() + "1");
			' play files




			backgroundTexture = content.Load(Of Texture2D)("Backgrounds/main_background")
			presentsTexture = content.Load(Of Texture2D)("Backgrounds/presents")
			authorsTexture = content.Load(Of Texture2D)("Backgrounds/author")
			titleTexture = content.Load(Of Texture2D)("Backgrounds/main_title")
			copyrightTexture = content.Load(Of Texture2D)("Backgrounds/copyright")

			'now for the text and other background like story etc
			text0BackgroudTexture = content.Load(Of Texture2D)("Backgrounds/text_0_background")
			text1BackgroudTexture = content.Load(Of Texture2D)("Backgrounds/text_1_background")
			text2BackgroudTexture = content.Load(Of Texture2D)("Backgrounds/text_2_background")


			backgroundToDisplayTexture = backgroundTexture
		End If
	End Sub


	''' <summary>
	''' Unloads graphics content for this screen.
	''' </summary>
	Public Overrides Sub Unload()
		'stop music 
		MediaPlayer.[Stop]()

		content.Unload()
	End Sub


	#End Region

	#Region "Update and Draw"


	''' <summary>
	''' Updates the background screen. Unlike most screens, this should not
	''' transition off even if it has been covered by another screen: it is
	''' supposed to be covered, after all! This overload forces the
	''' coveredByOtherScreen parameter to false in order to stop the base
	''' Update method wanting to transition off.
	''' </summary>
	Public Overrides Sub Update(gameTime As GameTime, otherScreenHasFocus As Boolean, coveredByOtherScreen As Boolean)
		MyBase.Update(gameTime, otherScreenHasFocus, False)
	End Sub


	''' <summary>
	''' Draws the background screen.
	''' </summary>
	Public Overrides Sub Draw(gameTime As GameTime)

		Dim spriteBatch As SpriteBatch = ScreenManager.SpriteBatch
		Dim viewport As Viewport = ScreenManager.GraphicsDevice.Viewport
		Dim fullscreen As New Rectangle(0, 0, viewport.Width, viewport.Height)

		spriteBatch.Begin()

		spriteBatch.Draw(backgroundToDisplayTexture, fullscreen, New Color(TransitionAlpha, TransitionAlpha, TransitionAlpha))

		If delay > 0 Then
			delay = delay - 0.1F
			If textureToDisplay IsNot Nothing Then
				TransitionAlphaTitle = TransitionAlphaTitle + 0.05F
				spriteBatch.Draw(textureToDisplay, New Rectangle(fullscreen.Width \ 2 - textureToDisplay.Width \ 2, fullscreen.Height \ 2, textureToDisplay.Width, textureToDisplay.Height), New Color(TransitionAlphaTitle, TransitionAlphaTitle, TransitionAlphaTitle))
				If textureToDisplay2line IsNot Nothing Then
					spriteBatch.Draw(textureToDisplay2line, New Rectangle(fullscreen.Width \ 2 - textureToDisplay2line.Width \ 2, fullscreen.Height - textureToDisplay2line.Height, textureToDisplay2line.Width, textureToDisplay2line.Height), New Color(TransitionAlphaTitle, TransitionAlphaTitle, TransitionAlphaTitle))
				End If
			End If
		Else
			numTexture += 1
			delay = 20F
			TransitionAlphaTitle = 0
			Select Case numTexture
				Case 1
					textureToDisplay = presentsTexture
					textureToDisplay2line = Nothing
					Exit Select
				Case 2
					textureToDisplay = authorsTexture
					textureToDisplay2line = Nothing
					Exit Select
				Case 3
					textureToDisplay = titleTexture
					textureToDisplay2line = copyrightTexture
					delay = 50F
					Exit Select
				Case 4
					backgroundToDisplayTexture = text0BackgroudTexture
					textureToDisplay = Nothing
					textureToDisplay2line = Nothing
					ResetTransition()
					delay = 40F
					Exit Select
				Case 5
					backgroundToDisplayTexture = text1BackgroudTexture
					textureToDisplay = Nothing
					textureToDisplay2line = Nothing
					ResetTransition()
					delay = 40F
					Exit Select
				Case 6
					backgroundToDisplayTexture = text2BackgroudTexture
					textureToDisplay = Nothing
					textureToDisplay2line = Nothing
					ResetTransition()
					delay = 40F
					Exit Select
				Case Else

					backgroundToDisplayTexture = backgroundTexture
					textureToDisplay = Nothing
					textureToDisplay2line = Nothing
					ResetTransition()
					numTexture = 0
					numLoops += 1
					Exit Select
			End Select
		End If



		spriteBatch.[End]()
	End Sub


	#End Region
End Class
